import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int V = in.nextInt();
        int[] v = new int[n + 1];
        int[] w = new int[n + 1];
        int index = 1;
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            v[index] = in.nextInt();
            w[index] = in.nextInt();
            index++;
        }
        int[] dp = new int[V + 1];
        for(int i = 1; i <= n; i++){
            for(int j = v[i]; j <= V; j++){
                dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
            }
        }
        System.out.println(dp[V]);
        int[] dp2 = new int[V + 1];
        for(int j = 1; j <= V; j++) dp2[j] = -1;
        for(int i = 1; i <= n; i++){
            for(int j = v[i]; j <= V; j++){
                if(dp2[j - v[i]] != -1)
                    dp2[j] = Math.max(dp2[j], dp2[j - v[i]] + w[i]);
            }
        }
        if(dp2[V] == -1) System.out.println(0);
        else System.out.println(dp2[V]);
    }
}